package com.dormitory.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dormitory.bean.DormitoryBean;
import com.dormitory.bean.NotificationBean;
import com.dormitory.view.NortifictionCard;
import com.dormitory.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by JHF on 2017/10/16.
 */

public class NotificationListAdapter extends BaseAdapter {

    private List<NotificationBean> mNotiList;
    private Activity mActivity;

    public NotificationListAdapter(Activity activity) {
        super();

        mNotiList = new ArrayList<NotificationBean>();
        for(int i=0;i<20;i++) {
        }
        mActivity = activity;
    }
    public void updateNotification(List<NotificationBean> notiList) {
        mNotiList = notiList;
        notifyDataSetChanged();
    }
    public void addNotification(NotificationBean notification) {
        mNotiList.add(notification);
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mNotiList.size();
    }

    @Override
    public Object getItem(int position) {
        return mNotiList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if(convertView != null) {
            view = convertView;
        }
        else {
            view = new NortifictionCard(mActivity);
        }
        NotificationBean notificationBean = mNotiList.get(position);
        ((TextView)view.findViewById(R.id.title)).setText(notificationBean.getTitle());
        ((TextView)view.findViewById(R.id.content)).setText(notificationBean.getContent());
        ((TextView)view.findViewById(R.id.text_user)).setText(notificationBean.getUserName());
        return view;
    }

}
